<template>
	<view>
		<!-- <view class="title">
			商家后台管理中心
		</view> -->
		<view class="title">
			<view class="title-one">大川</view>
			<view class="title-two">商家后台管理中心，让私域成为品牌基石</view>
			<!-- <view class="title-two">商家后台管理中心</view> -->
		</view>
		<!-- <view class="change">
			<view class="" :class="index==1?'change-one':''"  @tap="change(1)">
				用户名登录
			</view>
			<view class="" :class="index==2?'change-one':''" @tap="change(2)">
				手机号一键登录
			</view>
		</view> -->
		<view class="" style="height: 500rpx;" v-if="index==1">
			<u--form labelPosition="top" :model="userInfo" :rules="rules" ref="uForm" label-width="200" :label-style="{ color: '#7cb5ff', fontSize: '32rpx',marginBottom:'10rpx' }">
				<u-form-item label="用户名" prop="userName" borderBottom ref="item1">
					<u-input v-model="userInfo.userName" border="none" color="#fff">
						<u-icon name="phone" color="#7cb5ff" size="23"  slot="prefix" margin="0 10px 0 0" type="tips"></u-icon>
					</u-input>
				</u-form-item>
				<u-form-item label="密码" prop="password" borderBottom ref="item1">
					<u-input v-model="userInfo.password" border="none" color="#fff" type="password">
						<u-icon name="lock" color="#7cb5ff" size="23"  slot="prefix" margin="0 10px 0 0" type="tips"></u-icon>
					</u-input>
				</u-form-item>
			</u--form>
			
			<view class="login" @tap="login()">立即登录</view>
		</view>
		<view class="" style="height: 500rpx;line-height: 500rpx;" v-else>
			<button  open-type="getPhoneNumber" @getphonenumber="getphonenumber">微信用户一键登录</button>
		</view>
		<view class="title1">
			<u-checkbox-group>
				<u-checkbox v-model="checked"  shape="circle" ></u-checkbox>
			</u-checkbox-group>
			请阅读
			<text @tap="btn()" style="border-bottom: 1rpx solid #7cb5ff;">《大川长风隐私政策》</text>
		</view>
		<view class="footer">
			<view class="title3">大川长风</view>
			<view class="title2">
				版本号：
				<text style="font-size: 20rpx;letter-spacing:1rpx">v{{ version }}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {login} from '../../utils/api.js'
export default {
	data() {
		return {
			checkboxValue1:'',
				userInfo: {
					userName: '',
					password: ''
				},
				index:1,
			rules: {
				'userName': {
					type: 'string',
					required: true,
					message: '请填写用户名',
					trigger: ['blur', 'change']
				},
				'password': {
					type: 'string',
					required: true,
					message: '请填写密码',
					trigger: ['blur', 'change']
				}
			},
			version: ''
		};
	},
	onLoad() {
		if(uni.getStorageSync('data')){
			this.userInfo.userName=uni.getStorageSync('data').userName
			this.userInfo.password=uni.getStorageSync('data').password
		}
	},
	onShow() {
		let miniProgram = wx.getAccountInfoSync();
		this.version = miniProgram.miniProgram.version;
	},
	methods: {
		change(num){
			this.index=num
		},
		login(){
			let data={
				userName:this.userInfo.userName,
				password:this.userInfo.password
			}
			uni.setStorage({
				key:'data',
				data:data
			})
			uni.showLoading()
			login(data).then(res=>{
				if(res.code==200){
					uni.setStorage({
						key:'userInfo',
						data:res.body
					})
					uni.showLoading()
					uni.showToast({
						icon:'success',
						title:res.msg
					})
					setTimeout(()=>{
						
						uni.switchTab({
							url:'/pages/goods/goods'
						})
					},500)
				}else{
					uni.showToast({
						icon:'error',
						title:res.msg
					})
				}
			})
			// uni.switchTab({
			// 	url:'/pages/index/index'
			// })
		},
		btn(){
			uni.navigateTo({
				url:'/pages/login/yszc/yszc'
			})
		},
		getphonenumber(e){
			console.log(e);
		}
	},
	onReady() {
		//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
		this.$refs.uForm.setRules(this.rules);
	}
};
</script>

<style lang="scss">
page {
	background-color: #1176fe;
	padding: 80rpx;
	box-sizing: border-box;
}
.title {
	color: #fff;
	margin-top: 250rpx;
	margin-bottom: 50rpx;
	.title-one {
		font-size: 62rpx;
		font-weight: 700;
	}
}
.change{
	display: flex;
	align-items: center;
	background-color: #ebeff4;
	padding:10rpx 20rpx;
	border-radius: 15rpx;
	font-size: 26rpx;
	width: 400rpx;
	margin-bottom: 20rpx;
	.change-one{
		padding:10rpx 20rpx;
		color:#2479ff;
		font-weight: 700;
		background-color: #fff;
		margin:0 20rpx;
		border-radius: 10rpx;
	}
	
}
.login {
	background-color: #fff;
	display: flex;
	justify-content: center;
	align-items: center;
	height: 80rpx;
	border-radius: 40rpx;
	margin-top: 80rpx;
	color: #2479ff;
}
.title1 {
	width: 100%;
	display: flex;
	justify-content: center;
	align-items: center;
	font-size: 24rpx;
	color: #7cb5ff;
	margin-top: 40rpx;
	text {
		
	}
}

.footer {
	width: 100%;
	position: fixed;
	bottom: 60rpx;
	.title2 {
		width: 600rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 24rpx;
		color: #7cb5ff;
		margin-bottom: 10rpx;
	}
	.title3 {
		width: 600rpx;
		font-weight: 700;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 32rpx;
		color: #7cb5ff;
	}
}
</style>
